<{css src="member.css" app='b2c'}>
<{include file="site/common/header.html" app="b2c"}>
<div class="member-main">
    <div>
       <div class="title">
	   <span style="float:left"><{t}>品牌列表<{/t}>
	   <span class="disc">|</span> 
	   <span id='add' class="disc add-icon" ><a href="javascript:void(0);" ><{t}>品牌申请<{/t}></a></span>
	   <span class="disc">|</span> 
	   <span id="apply" class="disc add-icon" ><a href="javascript:void(0);" ><{t}>品牌使用申请<{/t}></a>
       </span>
	   </span>
	   </div>
        <!------------------>
	   <div id='add_div' <{if !$id}>style="display:none"<{/if}>>
            <form method="post" action="<{link app=business ctl=site_brand act=save}>" id="brand">
                <div class="division" style="border:none; border-bottom:1px dashed #ddd">
                    <{input type="hidden" name="id" value=$id}>
                <table width="100%" border="0" cellpadding="0" cellspacing="0" class="pplist">
                <tr>
                <th style="text-align:right"><{t}>品牌名称：<{/t}></th>
                <td>
                <{if !$id}>
                <{input type="text" name="brand_name" id="brand_name" style="width:120px" required="true" value=$brand_name onblur="nameCheck(this);"}><span id="check"></span>
                <{else}>
                <{input type="text" name="brand_name" id="brand_name" style="width:120px" required="true" value=$brand_name readonly="readonly"}><span id="check"></span>
                <{/if}>
                </td>
                </tr>
                <!--添加经营范围-->
                <tr>
                <th style="text-align:right"><{t}>所属分类：<{/t}></th>
                <td>
                <{input type="select" name="store_cat" options=$storeregion value=$store_cat  required="true"  }>
                </td>
                <td></td>
                </tr>
                <!--经营范围-->
                <!--添加品牌别名-->
                <tr>
                <th style="text-align:right"><{t}>品牌英文名称：<{/t}></th>
                <td>
                <{input type="text" name="brand_keywords" id="brand_keywords" style="width:120px" required="true" value=$brand_keywords }>
                </td>
                </tr>
                <!--添加品牌别名-->

                <tr>
                <th style="text-align:right"><{t}>网址：<{/t}></th>
                <td><{input type="text" name="brand_url" style="width:120px" value=$brand_url}></td>
                </tr>
                <tr>
                <th style="text-align:right">LOGO：</th>
                <td>
                <{input type='vimage' name='brand_logo' width=200 height=100 value=$brand_logo}>
                </td>
                </tr>

                <!--上传品牌资质文件-->
                <tr>
                <th style="text-align:right"><{t}>上传品牌资质文件：<{/t}></th>
                <td><{input type="vimage" name="brand_aptitude" width=200 height=100 value=$brand_aptitude}></td>
                </tr>
                <!--上传品牌资质文件-->

                <tr>
                <th style="text-align:right"><{t}>详细说明：<{/t}></th>
                <td><{input type="textarea" name="brand_desc" cols="80" rows="5" value=$brand_desc}></td>
                </tr>
                </table>
                </div>
                <div style="padding-left:142px; ">
                <{if !$id}>
                        <span style="float:left; margin-left:8px"><{button class="btn submit-btn" type="button" id="btn" rel="_request" label=$___b2c="提交"|t:'b2c'}></span>
                <{else}>
                        <span style="float:left; margin-left:8px"><{button class="btn submit-btn" type="button" id="btn_edit" rel="_request" label=$___b2c="编辑"|t:'b2c'}></span>
                <{/if}>
                        <span class="float-span" style="float:left;"><{button id="unset" type="button" label=$___b2c="取消"|t:'b2c'}></span>
                </div>
            </form>
        </div>
		<!------>

        <!------------------>
	   <div id='apply_div' style="display:none">
            <form method="post" action="<{link app=business ctl=site_brand act=applyStatus}>">
                <div class="division" style="border:none; border-bottom:1px dashed #ddd">
                    <table cellpadding="0" class="forform" cellspacing="0" border="0">
                        <tr><th><{t}>品牌使用申请<{/t}></th><td><{input type="vobject" object="brand" return_url="{$return_url}" filter=$goodslink_filter multiple="true" rowselect="true" textcol="brand_name" name="linkid" value=$goods.glink.items }></td></tr>
                    </table>
                </div>
                <div style="padding-left:142px; ">
                    <span class="float-span" style="float:left; margin-left:8px">
                        <{button id="unset1" type="button" label=$___b2c="取消申请"|t:'b2c'}>
                    </span>
                    <span style="float:left">
                        <{button class="btn submit-btn" type="submit" rel="_request" label=$___b2c="申请"|t:'b2c'}>
                     </span>
                </div>
            </form>
        </div>
		<!------>
        <table class="gridlist border-all mt10" width="100%" border="0" cellspacing="0" cellpadding="0" style="table-layout:fixed;">
            <tr>
                <th  class="bln"><{t}>品牌名称<{/t}></th>
                <th><{t}>品牌英文名称<{/t}></th>
				<th><{t}>品牌图标<{/t}></th>
                <th><{t}>品牌资质文件<{/t}></th>
				<th><{t}>审核状态<{/t}></th>
                <th><{t}>操作<{/t}></th>
				<th><{t}>详细说明<{/t}></th>
                <th><{t}>不通过原因<{/t}></th>
            </tr>
           <{foreach from=$data item=data key=key}>
            <tbody>
                <tr> 
                    <td class="textcenter"><{$data.brand_name}></td>
                    <td class="textcenter"><{$data.brand_keywords}></td>
                    <td class="textcenter"><div class='product-list-img member-gift-pic goodpic' isrc="<{$data.brand_logo|default:$defaultImage|storager:'s'}>" ghref="<{$data.brand_logo|default:$defaultImage|storager:'s'}>"><img src='<{$env.app.res_url}>/images/loading.gif' width="50px" height="50px"/></div></td>
					<td class="textcenter"><div class='product-list-img member-gift-pic goodpic' isrc="<{$data.brand_aptitude|default:$defaultImage|storager:'s'}>" ghref="<{$data.brand_aptitude|default:$defaultImage|storager:'s'}>"><img src='<{$env.app.res_url}>/images/loading.gif' width="50px" height="50px"/></div></td>
					<td class="textcenter"><{if $data.status == '0'}>审核中<{elseif $data.status == '1'}>审核通过<{elseif $data.status == '2'}>审核不通过<{/if}></td>
                    <td align="center"><{if $data.type == '0'}><{if $data.status !=1}><a href="<{link app=business ctl=site_brand act=return_brand arg0=$pager.current arg1=$data.id}>">编辑</a>&nbsp;&nbsp;&nbsp;&nbsp;<a href="javascript:remove(<{$data.id}>);">删除</a><{/if}><{/if}>
					<{if $data.type == '1'}><{if $data.status == '2'}><a href="javascript:remove(<{$data.id}>);">删除</a><{/if}><{/if}>
					</td>
					<td align="center"><{$data.brand_desc}></td>
                    <td align="center"><{$data.fail_reason}></td>
                </tr>
            </tbody>
		<{/foreach}>
        </table>
<div style="float:right"><{pagers data=$pager}></div>
     </div>
</div>
<script>
$("add").addEvent('click',function(e){      
                $('add_div').setStyle('display','inline');
                $('apply_div').setStyle('display','none');
});
$("unset").addEvent('click',function(e){
            $('add_div').setStyle('display','none');
        });
function a(url,options){
        if(!url) return;
        options = Object.append({
            width:window.getSize().x*0.8,
            height:window.getSize().y*0.8
        },options||{});
        var params = 'toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width={width},height={height}';
        params = params.substitute(options);

        window.open(url,'_blank',params);
    }
$("apply").addEvent('click',function(e){      
                $('apply_div').setStyle('display','inline');
                $('add_div').setStyle('display','none');
});
$("unset1").addEvent('click',function(e){
            $('apply_div').setStyle('display','none');
        });
 function nameCheck(input){

        new Request.HTML({
            url:'<{link app=business ctl=site_brand act=namecheck}>',
            update:$(input).getNext(),
            method:'post',
            data:'brand_name='+encodeURIComponent(input.value.trim())
        }).send();
    }
if($('btn')){
    $('btn').addEvent('click',function(e){
        if($('check').innerHTML =='<span class="font-green">&nbsp;可以使用</span>'||$('check').innerHTML =='<SPAN class=font-green>&nbsp;可以使用</SPAN>'){
           $('brand').submit();
        }else{
           e.stop();
           return;
        }
   });
}
if($('btn_edit')){
    $('btn_edit').addEvent('click',function(){
		   $('brand').submit();
		
   });
}
function brand_apply(){
		var apply = "<{link app=business ctl='site_brand' act='brand_apply'}>";
		quickPassport(apply, '<{t}>新增品牌申请<{/t}>');
	}

	function quickPassport(url, title){
    new Ex_Dialog(url, {
        title: title,
        width: 500,
		height:500,
        modal: true,
        onLoad:function(){
            
        },
        asyncOptions: {
            
            onSuccess: function() {
                var ifm = this.content.getElement('iframe');
                var ifmWin = ifm.contentWindow || ifm.window;
                this.setTitle(title);
                ifm.setStyle('height', Math.min(ifmWin.getScrollSize().y,window.getSize().y-this.header.getSize().y-this.content.getPatch().y-this.body.getPatch().y-this.container.getPatch().y));
                this.container.position();
            }
        }
    });
	}

 function brand_use_apply(){
       var use_apply = "<{link app=business ctl='site_brand' act='use_apply'}>";
		quickPassport(use_apply, '<{t}>品牌使用申请<{/t}>');
 }

 function brand_edit(id){
       var edit = "<{link app=business ctl='site_brand' act='brand_apply'}>";
		Edit(edit, '<{t}>编辑<{/t}>',id);
 }

 function Edit(url, title,id){
    new Ex_Dialog(url, {
        title: title,
        width: 500,
		height:500,
        modal: true,
        onLoad:function(){
            
        },
        asyncOptions: {
            data: 'id='+id,
            onSuccess: function() {
                var ifm = this.content.getElement('iframe');
                var ifmWin = ifm.contentWindow || ifm.window;
                this.setTitle(title);
                ifm.setStyle('height', Math.min(ifmWin.getScrollSize().y,window.getSize().y-this.header.getSize().y-this.content.getPatch().y-this.body.getPatch().y-this.container.getPatch().y));
                this.container.position();
            }
        }
    });
	}

    function remove(id) {
	 Ex_Dialog.confirm('<{t}>确定要删除该项吗？<{/t}>', function(e){
		if(!e) return;
		new Request.JSON({
			url:"<{link app=business ctl='site_brand' act='brand_move' }>",
			data:'id='+id,
			method:'POST',
			onSuccess:function(rs){
			
			  Ex_Dialog.alert(rs.message);
			
			  window.location.reload();
			}
		  }).send();
	});
 }
</script>


<script>
  window.addEvent('domready', function(){
    var cart_product_img_viewer=new Element('div',{styles:{'position':'absolute','zIndex':500,'opacity':0,'border':'1px #666 solid'}}).inject(document.body);
    var cpiv_show=function(img,event){
        if(!img)return;
        cart_product_img_viewer.empty().adopt($(img).clone().removeProperties('width','height').setStyle('border','1px #fff solid')).fade(1);

        var size = window.getSize(), scroll = window.getScroll();
        var tip = {x: cart_product_img_viewer.offsetWidth, y: cart_product_img_viewer.offsetHeight};
        var props = {x: 'left', y: 'top'};
        for (var z in props){
            var pos = event.page[z] + 10;
            if ((pos + tip[z] - scroll[z]) > size[z]) pos = event.page[z] - 10 - tip[z];
            cart_product_img_viewer.setStyle(props[z], pos);
        }

    };

    $$('.product-list-img').each(function(i){
        new Asset.image(i.get('isrc'),{onload:function(img){
            if(!img)return;
            var _img=img.zoomImg(50,50);
            if(!_img)return;
            _img.setStyle('cursor','pointer').addEvents({
                'mouseenter':function(e){
                    cpiv_show(_img,e);
                },
                'mouseleave':function(e){
                    cart_product_img_viewer.fade(0);
                }
            });
            i.empty().adopt(new Element('a',{href:i.get('ghref'),target:'_blank',styles:{border:0}}).adopt(_img));
            },onerror:function(){
                i.empty();
        }});

    });
    
  });
</script>